package com.ict.web.controller.yzq;

import com.ict.web.domain.IotDeviceInfo;
import com.ict.web.dto.InsertIotDeviceInfoDto;
import com.ict.web.dto.UpdateIotDeviceInfoDto;
import com.ict.web.service.IIotDeviceInfoService;
import com.ict.web.vo.IntensificationExamineVo;
import com.ict.web.vo.IotDeviceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ict.common.annotation.Log;
import com.ict.common.core.controller.BaseController;
import com.ict.common.core.domain.AjaxResult;
import com.ict.common.enums.BusinessType;
import com.ict.common.core.page.TableDataInfo;

import java.text.ParseException;
import java.util.List;

/**
 * 物联设备信息Controller
 * 
 * @author ruoyi
 * @date 2022-03-07
 */
@Api(tags = "物联设备")
@RestController
@RequestMapping("/system/iotDeviceInfo")
public class IotDeviceInfoController extends BaseController
{
    @Autowired
    private IIotDeviceInfoService iotDeviceInfoService;

    /**
     * 查询物联设备信息列表
     */
    @ApiOperation("查询物联设备列表")
    @GetMapping("/list")
    public TableDataInfo list()
    {
        startPage();
        List<IotDeviceInfo> list = iotDeviceInfoService.selectIotDeviceInfoList();
        return getDataTable(list);
    }


    /**
     * 获取物联设备信息详细信息
     */
    @ApiOperation("获取物联设备信息详细信息")
    @GetMapping(value = "/{lotDeviceId}")
    public AjaxResult getInfo(@PathVariable("lotDeviceId") Long lotDeviceId)
    {
        return AjaxResult.success(iotDeviceInfoService.selectIotDeviceInfoByLotDeviceId(lotDeviceId));
    }

    /**
     * 新增物联设备信息
     */
    @ApiOperation("新增物联设备信息")
    @Log(title = "物联设备信息", businessType = BusinessType.INSERT)
    @PostMapping("/addSave")
    public AjaxResult add(Long programmeId,@RequestBody InsertIotDeviceInfoDto addDto)
    {
        return toAjax(iotDeviceInfoService.insertIotDeviceInfo(programmeId,addDto));
    }

    /**
     * 修改物联设备信息
     */
    @ApiOperation("修改物联设备信息")
    @Log(title = "物联设备信息", businessType = BusinessType.UPDATE)
    @PutMapping("/editSave")
    public AjaxResult edit(@RequestBody UpdateIotDeviceInfoDto updateDto)
    {
        return toAjax(iotDeviceInfoService.updateIotDeviceInfo(updateDto));
    }

    /**
     * 删除物联设备信息
     */
    @ApiOperation("删除物联设备信息")
    @Log(title = "物联设备信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lotDeviceId}")
    public AjaxResult remove(@PathVariable Long lotDeviceId)
    {
        return toAjax(iotDeviceInfoService.deleteIotDeviceInfoByLotDeviceId(lotDeviceId));
    }

    @GetMapping("/getIntensificationExamineVo/{proId}")
    @ApiOperation("集约化检测查询")
    public IntensificationExamineVo getIntensificationExamineVo(@PathVariable Long proId) throws ParseException {
        return iotDeviceInfoService.getIntensificationExamineVo(proId);
    }
    @GetMapping("/getDeviceName")
    @ApiOperation("物联设备名字")
    public AjaxResult getDeviceName() {
//        String depetList = HttpUtil.createPost("http://100.112.4.120:60010/out/getDeviceInfo").execute().body();
//        List<GetIotDeviceInfoVo> getIotDeviceInfoVoList = JSONArray.parseArray(depetList, GetIotDeviceInfoVo.class);
//        List<GetIotDeviceInfoVo> collect1 = getIotDeviceInfoVoList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() ->
//                new TreeSet<>(Comparator.comparing(GetIotDeviceInfoVo::getName))), ArrayList::new));
//        List<String> collect = collect1.stream().map(GetIotDeviceInfoVo::getName).collect(Collectors.toList());
        //物联平台-产品下无设备的产品：{"水压检测器","智能车闸","智慧城管化粪池","烟雾火灾报警器","可燃气体报警器","垃圾分类检测器","组合式电气火灾探测器","智能灯杆报警器"}
        String[] collect = new String[]{"空气微站","流量计","雨量计","烟雾报警器","一键求助终端","化粪池满溢监测器","沼气检测器","空气质量监测器"
                ,"泵站","水质检测器"};
        return AjaxResult.success(collect);
    }
    @PostMapping("/select")
    @ApiOperation("集约化检测产品id查询产品设备信息")
    public AjaxResult select(@RequestBody List<String> list,
                                    @RequestParam("pageSize") int pageSize,@RequestParam("pageNum") int pageNum) throws ParseException {
        List<IotDeviceVo> select = iotDeviceInfoService.select(list);
        return AjaxResult.success()
                .put("pageSize",pageSize)
                .put("pageNum",pageNum)
                .put("total",select.size())
                .put("data",select.size()!=0?iotDeviceInfoService.selectPage(select,pageSize,pageNum):"");
    }
}
